package com.demo.controller.flighttime;

import com.demo.common.model.Airroute;
import com.demo.common.model.Flighttime;
import com.demo.controller.airroute.AirrouteValidator;
import com.demo.interceptor.WebInterceptor;
import com.demo.service.AirrouteService;
import com.demo.service.FlightTimeService;
import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.kit.Kv;
import com.jfinal.kit.StrKit;

/**
 * 航班管理
 */
@Before(WebInterceptor.class)
public class FlightTimeController extends Controller {

    @Inject
    FlightTimeService flightTimeService;

    public void index() {
        Kv cond=Kv.create();
        if(StrKit.notBlank(getPara("flighttimeno"))){
            cond.set("flighttimeno",getPara("flighttimeno"));
        }
        if(StrKit.notBlank(getPara("airno"))){
            cond.set("airno",getPara("airno"));
        }
        if(StrKit.notBlank(getPara("begin"))){
            cond.set("begin",getPara("begin"));
        }
        if(StrKit.notBlank(getPara("end"))){
            cond.set("end",getPara("end"));
        }
        setAttr("flighttimePage", flightTimeService.paginate(getParaToInt(0, 1), 10,Kv.by("cond",cond)));
        render("flighttime.html");
    }

    public void add() {
    }

    /**
     * save 与 update 的业务逻辑在实际应用中也应该放在 serivce 之中，
     * 并要对数据进正确性进行验证，在此仅为了偷懒
     */
    @Before(FlightTimeValidator.class)
    public void save() {
        getBean(Flighttime.class).save();
        redirect("/flighttime");
    }

    public void edit() {
        setAttr("flighttime", flightTimeService.findById(getParaToInt()));
    }

    /**
     * save 与 update 的业务逻辑在实际应用中也应该放在 serivce 之中，
     * 并要对数据进正确性进行验证，在此仅为了偷懒
     */
    @Before(FlightTimeValidator.class)
    public void update() {
        getBean(Flighttime.class).update();
        redirect("/flighttime");
    }


    public void delete() {
        flightTimeService.deleteById(getParaToInt());
        redirect("/flighttime");
    }

    public void verify(){
        Flighttime flighttime=flightTimeService.findById(getParaToInt());
        flighttime.setVerify(1);
        flighttime.update();
        redirect("/flighttime");
    }
}
